/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package group2assignone.model;

import java.util.ArrayList;

/**
 *
 * @author Natalie
 */
public class TicketComposite extends TicketComponent
{
    private ArrayList tickets = new ArrayList();
    private boolean booked = false;

    @Override
    public void addTicket(TicketComponent ticket)
    {
        tickets.add(ticket);
    }


    public int bookTicket(int bookingNum, int itemNumber)
    {
        System.out.println("Composite of Tickets being booked");
        
        
        for(int i = 0; i<tickets.size(); i++)
        {
           TicketComponent comp =  (TicketComponent) tickets.get(i);

           itemNumber = comp.bookTicket(bookingNum, itemNumber);
           booked = booked || comp.isBooked();
        }

        return itemNumber;
    }

    public double getCost()
    {
        double cost = 0;

        for(int i = 0; i<tickets.size(); i++)
        {
           TicketComponent comp = (TicketComponent) tickets.get(i);
           cost += comp.getCost();
        }

        return cost;
    }

    public boolean containsFlight(String flightNum)
    {
        boolean exists = false;

        for(int i = 0; i<tickets.size(); i++)
        {
           TicketComponent comp = (TicketComponent) tickets.get(i);
           exists = exists || comp.containsFlight(flightNum);
        }

        return exists;
    }

    public boolean isBooked()
    {
        return booked;
    }
}
